<?php
    $store = Mage::app()->getStore();
    $code  = $store->getCode();
?>
<script type="text/javascript">
	jQuery(function($){
		var scrolled = false;
		$(window).scroll(function(){
			    if(140<$(window).scrollTop() && !scrolled){
                    if(!$('.header-container .menu-wrapper .mini-cart').length && !$('.header-container .menu-wrapper .sticky-logo').length){
				        $('.header-container').addClass("sticky-header");
				        var minicart = $('.header-container .mini-cart').html();
				        $('.header-container .menu-wrapper').append('<div class="mini-cart">'+minicart+'</div>');
                    <?php if(Mage::getStoreConfig('porto_settings/header/sticky_header_logo', $code)): ?>
                        var logo_image = $('<div>').append($('.header-container .header > .logo').clone()).html();
                        $('.header-container .menu-wrapper').prepend('<div class="sticky-logo">'+logo_image+'</div>');
                        <?php if(Mage::getStoreConfig('porto_settings/header/sticky_header_logo_img', $code)):?>
                        $(".sticky-logo img").attr("src","<?php echo $this->getSkinUrl(Mage::getStoreConfig('porto_settings/header/sticky_header_logo_img', $code)); ?>");
                        <?php endif; ?>
                    <?php endif; ?>
				        $('.header-container .header-wrapper > div').each(function(){
					        if($(this).hasClass("container")){
						        $(this).addClass("already");
					        } else {
						        $(this).addClass("container");
					        }
				        });
				        scrolled = true;
                    }
			    }
			    if(140>=$(window).scrollTop() && scrolled){
				    $('.header-container').removeClass("sticky-header");
				    $('.header-container .menu-wrapper .mini-cart').remove();
                <?php if(Mage::getStoreConfig('porto_settings/header/sticky_header_logo', $code)): ?>
                    $('.header-container .menu-wrapper > .sticky-logo').remove();
                <?php endif; ?>
				    scrolled = false;
				    $('.header-container .header-wrapper > div').each(function(){
					    if($(this).hasClass("already")){
						    $(this).removeClass("already");
					    } else {
						    $(this).removeClass("container");
					    }
				    });
			    }
		});
	});
</script>